package com.zsy.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zsy.entity.User;
import com.zsy.mapper.UserMapper;
import com.zsy.model.JwtUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @Author: Zhou ShiYang
 * @Description:
 * @Date:Create：in 2020/10/13 17:04
 **/
@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        User user = userMapper.selectOne(Wrappers.<User>lambdaQuery()
                .eq(User::getUsername, s));
        return new JwtUser(user);
    }

}

